<?php
	require("frmCookie.php");
?>
<html>
	<head>
    	<?php
		require("frmHeader.php");
		?>
		<script language="javascript" src="scripts/ajax.js"></script>
		<script language="javascript" src="scripts/validar.js"></script>
		<script language="javascript">
		
		function showStock()
		{
			xmlHttp = GetXmlHttpObject();
			if (xmlHttp == null)
  			{
  				alert ("Your browser does not support AJAX!");
  				return;
  			}
  			 
			var url = "ajaxStock.php";
			url = url + "?q=" + frm.txtParte.value;
			url = url + "&sid=" + Math.random();
			xmlHttp.onreadystatechange = stateChangedStock;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}

		function stateChangedStock() 
		{ 
			if (xmlHttp.readyState == 4)
			{ 
				document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
			}
		}
			
		function search(str, evt, list, text, op, ajax)
		{ 
			option = op;
			
			var charCode = (evt.which) ? evt.which : event.keyCode;
			
			if (charCode == 13)
			{
				try
				{
					if(document.getElementById(list).options.length == 1)
					{
						if(op != 4)
						{
							document.getElementById(text).value = document.getElementById(list).options[0].text;
							document.getElementById(ajax).innerHTML = "";
							showStock();
							str = "";
						}
					}
					else if(document.getElementById(list).options.length > 1)
					{
						document.getElementById(list).options[0].selected = 1;
						document.getElementById(list).focus();
					}
					
				}
				catch(e)
				{
					//NO HAGO NADA PORQUE TODAVIA NO HUBO BUSQUEDA
				}
			}
			
			if (charCode != 13)
			{
				xmlHttp = GetXmlHttpObject();
				if (xmlHttp == null)
	  			{
	  				alert ("Your browser does not support AJAX!");
	  				return;
	  			}
	  			var acc = ""; 
				var url = "ajaxOrden.php";
				url = url + "?q=" + str;
				url = url + "&op=" + op;
				url = url + "&sid=" + Math.random();
				xmlHttp.onreadystatechange = stateChanged;
				xmlHttp.open("GET",url,true);
				xmlHttp.send(null);
			}
		}

		function stateChanged() 
		{ 
			if (xmlHttp.readyState == 4)
			{ 
				document.getElementById("txtPartes").innerHTML = xmlHttp.responseText;
			}
		}

		function GetXmlHttpObject()
		{
			var xmlHttp = null;
			try
  			{
	 	 		// Firefox, Opera 8.0+, Safari
  				xmlHttp = new XMLHttpRequest();
  			}
			catch (e)
  			{
  				// Internet Explorer
  				try
    			{
    				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    			}
  				catch (e)
    			{
    				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    			}
  			}
			return xmlHttp;
		}
		
		function tomaOpcion(obj, i, evt)
		{
			var charCode = (evt.which) ? evt.which : event.keyCode;
			
			if (charCode == 13)
			{
				frm.txtParte.value = obj.options[i].text;
				document.getElementById("txtPartes").innerHTML = "";
				showStock();
			}
		}	
		
		function valida()
		{
			
			if(frm.txtParte.value == "")
			{
				alert("Por favor ingrese la Parte.");
				frm.txtParte.focus();
				return false;
			}
			
			return false;
		}
		</script>
	</head>
	<body>
    	<table cellpadding="0" cellspacing="0" align="center" class="tablaPrincipal">
        	<tr>
            	<td align="center">
                	<?php
					require("frmSession.php"); 
					
					//Redirecciona a SINPERMISOS.PHP en caso de no tener permisos
					
					if (!(in_array(12005, $_SESSION[permisos])))
					{
					?>
					  <script language="JavaScript" type="text/javascript">
					  <!--
					  window.location.href = "sinPermisos.php"
					  //-->
					  </script>
					<?php
					}
					$titulo = "Consulta de STOCK";
					
					?>
                </td>
            </tr>
            <tr>
            	<td align="center">
                	<?php
					require("frmTitulo.php");
					?>
                </td>
            </tr>
            <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
            	<td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="menuPrincipal">
                    	<tr>
                        	<td>
								<?php
                                require("frmMenu.php");
                                ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="tituloPantalla">
                    	<tr>
                        	<td align="center">
                            	<p class="texto" align="left"><?php echo $titulo; ?></p>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
             <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="estadoPantalla">
                    	<tr>
                        	<td align="center">
                            	<p class="texto" align="left"><?php echo $mensaje; ?></p>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
             <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="contenedorPrincipal">
                    	<tr>
                        	<td align="">
                        		<form name="frm" action="" method="post" onSubmit="return valida();">
		                			<table>
		                				<tr>
            								<td>Parte: </td>
            								<td><input type="text" name="txtParte" size="40" maxlength="100" onKeyUp="search(this.value, event, 'lstPartes', 'txtParte', 45, 'txtPartes');document.getElementById('partes').style.display='';" /></td>
            							</tr>
            							<tr id="partes" style="display:none;">
	                						<td colspan="2"><div id="txtPartes"></div></td>
	                					</tr>
		                				<tr>
		                					<td colspan="2" align="center"><input type="button" name="cmdEnviar" value="Consultar" onClick="valida();" /></td>
		                				</tr>
		                			</table>
		                			<table>
		                				<tr>
		                					<td><div id="txtHint"></div></td>
		                				</tr>
		                			</table>
        		            	</form>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
	</body>
</html>